package com.axe.processdatasync;

import android.app.Application;
import android.content.ContentResolver;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        registerBroadcastReciver();

        syncData();
    }

    private void registerBroadcastReciver() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.axe.process.data.action");
        MyDataBrodcastReciver brodcastReciver = new MyDataBrodcastReciver();
        this.registerReceiver(brodcastReciver, intentFilter);
    }

    /**
     * 同步数据
     */
    private void syncData() {
        ContentResolver contentResolver = getContentResolver();
        Uri uri = Uri.parse("content://com.axe.processdatasync.test.data");
        Bundle bundle = contentResolver.call(uri,"syncData",null,new Bundle());
        String data = bundle.getString("data");
        Toast.makeText(this, "ContentProvider:"+data,Toast.LENGTH_SHORT).show();
    }
}
